﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using DecisionFramework.Logging;

namespace DecisionFramework.Logging.Internal
{
	/// <summary>
	/// Provides an ILogService implementation that 
    /// determines the company name and container name
    /// from app settings and writes app events to the
    /// event viewer to a log with the same names as
    /// the company name.
	/// </summary>
	/// <remarks>  
	/// Author: Greg Cowin
	/// </remarks> 	 
	public class EventViewerLogService :  ILogService
	{
        /// <summary>
        /// Determines the company name.
        /// </summary>
        /// <returns>The company name.</returns>
        private string DetermineCompanyName()
        {
            return LoggingAppSettings.CompanyName;
        }

        /// <summary>
        /// Determines the container name.
        /// </summary>
        /// <returns></returns>
		private string DetermineContainerName()
		{
			return LoggingAppSettings.ContainerName; 
		}

		private IChannel _admin;
        /// <summary>
        /// Admin: support events that target end users, administrators, and support personnel.
        /// </summary>
		public IChannel Admin
		{
			get
			{
				if (_admin == null)
					_admin = new Channel(ChannelType.Admin, DetermineCompanyName(), DetermineContainerName());
				return _admin;
			}
		}

		private IChannel _operational;
        /// <summary>
        /// Operational: support events that are used for analyzing and diagnosing a problem or occurrence.
        /// </summary>
		public IChannel Operational
		{
			get
			{
				if (_operational == null)
                    _operational = new Channel(ChannelType.Operational, DetermineCompanyName(), DetermineContainerName());
				return _operational;
			}
		}

		private IChannel _analytic;
        /// <summary>
        /// Analytic: support events that are published in high volume.
        /// </summary>
		public IChannel Analytic
		{
			get
			{
				if (_analytic == null)
                    _analytic = new Channel(ChannelType.Analytic, DetermineCompanyName(), DetermineContainerName());
				return _analytic;
			}
		}

		private IChannel _debug;
        /// <summary>
        /// Debug: support events that are used solely by developers to diagnose a problem for debugging. Comes with 
        /// a possible performance penalty.
        /// </summary>
		public IChannel Debug
		{
			get
			{
				if (_debug == null)
                    _debug = new Channel(ChannelType.Debug, DetermineCompanyName(), DetermineContainerName());
				return _debug;
			}
		}
	}
}
